package com.situ.store.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.situ.store.entity.User;
import com.situ.store.service.UserService;
import com.situ.store.service.impl.UserServiceImpl;
import com.situ.store.util.BaseController;
import com.situ.store.vo.LayuiTableVO;
import com.situ.store.vo.ResVO;

@WebServlet("/user")
public class UserController extends BaseController {

	private static final long serialVersionUID = 1L;
	UserService ser = new UserServiceImpl();
	
	// 修改密码
	public ResVO changePwd(String newPwd, HttpSession session) {
		return ser.changePwd(newPwd, session);
	}

	// 验证旧密码是否一致
	public ResVO checkOldPwd(String oldPwd, HttpSession session) {
		return ser.checkOldPwd(oldPwd, session);
	}

	// 用户主页
	public void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req, resp);
	}

	// 删除用户
	public void del(Integer id) throws IOException {
		ser.del(id);
	}

	// 重置密码
	public void resetPwd(Integer id){
		ser.resetPwd(id);
	}

	// 修改用户信息
	public ResVO edit(Integer id) throws IOException {
		return ser.selectById(id);
	}

	// 保存或编辑
	public ResVO save(User user, HttpSession session) throws IOException {
		return ser.save(user, session);
	}

	// 查询用户信息
	public LayuiTableVO userList(Integer page, Integer limit, String keyword) throws IOException {
		return ser.userList(page, limit, keyword);
	}

}
